include ../config.mk

JOBS=$(shell grep -c ^processor /proc/cpuinfo)
ifeq ($(JOBS),)
JOBS = 1
endif

default: QM102V_CUSTOM

help:
	@echo "usage:"
	@echo "    make QM102V"
	@echo "    make QM102V_CUSTOM"

	@echo "    make menuconfig"

QM102V:
	if [ ! -d uboot ]; then tar xf uboot.tar.gz; fi;\
	cd uboot; make clean; \
	export CROSS_COMPILE=$(CROSS_COMPILE); \
	export BUILD_DIR=./_build;\
	if [ ! -e .config ]; then make qm102v_defconfig; fi; \
	make all -j$(JOBS) ; 

QM102V_CUSTOM:
	if [ ! -d uboot ]; then tar xf uboot.tar.gz; fi;\
	cd uboot; make clean; \
	export CROSS_COMPILE=$(CROSS_COMPILE); \
	export BUILD_DIR=./_build;\
	echo "BUILD_DIR: $(BUILD_DIR)"; \
	echo "CONFIG_UBOOT_DEFCONFIG: $(CONFIG_UBOOT_DEFCONFIG)"; \
	if [ ! -e .config ]; then make $(CONFIG_UBOOT_DEFCONFIG); fi; \
	cp board/fullhan/qm102v/$(CONFIG_UBOOT_BOARD_NAME)/qm102v.h include/configs/qm102v.h || exit $?; \
	make all -j$(JOBS) ; 


menuconfig:
	@if [ ! -d uboot ]; then tar xf uboot.tar.gz; fi
	@cd uboot; \
    if [ ! -e .config ]; then \
        echo "run [cd uboot; make <chip>_defconfig] first !"; \
        exit 1; \
    fi; \
    make menuconfig

clean:
	cd uboot && make clean

distclean:
	cd uboot && make distclean